<template>
  <!-- 授权记录 -->
  <div class="authorize-record">
    <div class="authorize-record-title blueTitleStyle">授权记录</div>
    <div class="authorize-record-content">
      <div class="filtrate-group">
        <el-form ref="form" :inline="true" :model="form" label-width="1rem">
          <el-row>
            <el-col :span="8">
              <el-form-item label="变电站:">
                <el-select v-model="form.stationName" filterable placeholder="请选择">
                  <el-option
                    v-for="item in stationName_options"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="区域房间:">
                <el-select v-model="form.areaName" placeholder="请选择">
                  <el-option
                    v-for="item in area_options"
                    :key="item.value"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="授权人:">
                <el-select v-model="form.authPerson" placeholder="请选择">
                  <el-option
                    v-for="item in authorizedPerson"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="被授权人:">
                <el-select v-model="form.bauthPerson" placeholder="请选择">
                  <el-option
                    v-for="item in isAuthorizedPerson"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="钥匙编号:">
                <el-select v-model="form.keyCode" placeholder="请选择">
                  <el-option
                    v-for="item in keyNum"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="是否派发多站:">
                <el-select v-model="form.sendstation" placeholder="请选择">
                  <el-option
                    v-for="item in isdDistribut"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="授权时间：">
                <el-date-picker
                  :style="{width: '100%'}"
                  v-model="form.strtimeedntime"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="endbox btn">
                <el-button type="primary" @click="handleSearch">查询</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="table-group bigTableStyle">
        <el-table
        border
          :data="tableData"
          :row-class-name="tableRowClassName"
          style="width: 100%"
          height="100%"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.5)"
        >
          <el-table-column type="index" label="序号" width="55"></el-table-column>
          <el-table-column prop="stationName" label="变电站" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="areaName" label="区域房间" width="100" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="accessName" label="门禁" width="100" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="keyCode" label="钥匙编号" width="100" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column
            prop="authstartTime"
            label="授权开始时间"
            width="120"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="authendTime"
            label="授权结束时间"
            width="120"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column prop="authPerson" label="授权人" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column
            prop="bauthPerson"
            label="被授权人"
            width="100"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="sendstation"
            label="是否同时派发多站"
            width="150"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <!-- <el-table-column prop="relevance" label="查看关联变电站" width="100">
            <template slot-scope="scope">
              <el-button type="primary">{{scope.row.relevance}}</el-button>
            </template>
          </el-table-column>-->
        </el-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { objType } from "@/utils/interface";
import { publicAPIModule } from "@/store/modules/public";
import { LocksAPIModule } from "@/store/modules/locks";
@Component
export default class AuthorizeRecord extends Vue {
  // 表单
  public form = {
    authorPersonVal: "",
    strtimeedntime: [],
    keyNumVal: "",
  };
  // 变电站
  get stationName_options() {
    return publicAPIModule.stationList;
  }
  // 区域房间
  get area_options() {
    return publicAPIModule.getAreaDictList;
  }
  get authorizedPerson() {
    return LocksAPIModule.getUserList;
  }
  get isAuthorizedPerson() {
    return LocksAPIModule.getUserList;
  }
  get keyNum() {
    return LocksAPIModule.getDeviceItemList;
  }
  // 是否派发多站
  isdDistribut: Array<object> = [
    {
      value: "1",
      label: "是",
    },
    {
      value: "2",
      label: "否",
    },
  ];
  //   表格
  tableData: Array<object> = [];
  loading: boolean = true;

  mounted() {
    this.fetch();
  }

  // 查询-获取授权记录列表信息接口
  fetch() {
    // console.log(9999999999999);

    var params = {
      areaId: "",
      authCode: "",
      authEndTime: "",
      authStartTime: "",
      bauthCode: "",
      keyCode: "",
      sendStation: "",
      stationId: "",
    };
    (this as any).$services
      .getAuthList({ data: params })
      .then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          this.tableData = res.data;
          this.loading = false;
        }
      })
      .catch((err: object) => {
        console.log(err);
        this.loading = false;
      });
  }
  handleSearch() {
    this.fetch();
  }

  // 表格隔行变色
  tableRowClassName({ row, rowIndex }: objType): string {
    // console.log(row, rowIndex);
    if (rowIndex % 2 === 0) {
      return "row1";
    } else {
      return "row2";
    }
  }
}
</script>

<style lang="scss" scoped>
.authorize-record {
  width: 100%;
  height: 100%;
  &-title {
    width: 100%;
    height: 0.26rem;
  }
  &-content {
    width: 100%;
    height: calc(100% - 0.26rem);
    .filtrate-group {
      width: 100%;
      height: 1.24rem;
      margin-top: 0.1rem;
      .btn {
        padding-right: 0.1rem;
      }
    }
    .table-group {
      width: 100%;
      height: calc(100% - 1.7rem);
      padding: 0 0.1rem;
      // margin: 0.2rem 0.14rem 0.2rem 0.14rem;
      overflow: auto;
    }
  }
}
</style>
<style lang="scss">
.authorize-record {
  // 按钮的高度
  // .el-button--primary {
  //   height: 0.26rem;
  // }
  // .el-button {
  //   padding: 0 0.15rem;
  // }
  // 时间
  .el-input--prefix {
    .el-input__inner {
      height: 0.26rem;
    }
    .el-input__icon {
      line-height: 0.26rem;
    }
  }
  // input框的高度{
  .el-select .el-input .el-input__inner {
    height: 0.26rem;
  }
  .el-form-item {
    margin-bottom: 0.1rem;
  }
  .el-form-item__content {
    width: calc(100% - 1rem);
  }
}
</style>